package ejb.facades.location;

import ejb.facades.AbstractFacade;
import entities.location.Address;
import entities.location.Country;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 * Trabalho PD - 2014/2015
 *
 * @author a21210380 a21210392
 */
@Stateless
public class AddressFacade extends AbstractFacade<Address> implements AddressFacadeLocal {

    @PersistenceContext(unitName = "Trabalho_PDPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public AddressFacade() {
        super(Address.class);
    }

    @Override
    public List<Address> findAllAddressFromCountry(Country country) {
        return em.createNamedQuery("Address.findByCountryId", Address.class)
                .setParameter(1, country.getIdCountry())
                .getResultList();
    }

}
